// 直接测试DeepSeek API
const https = require('https');

const apiKey = 'sk-493d502eee42490f92d3015479aa8f47';
const baseUrl = 'https://api.deepseek.com';

const data = JSON.stringify({
  model: 'deepseek-chat',
  messages: [
    {
      role: 'system',
      content: 'You are RoleRealm AI assistant.'
    },
    {
      role: 'user',
      content: '你好，请介绍一下你自己'
    }
  ],
  temperature: 0.7,
  max_tokens: 1000
});

const options = {
  hostname: 'api.deepseek.com',
  port: 443,
  path: '/v1/chat/completions',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${apiKey}`,
    'Content-Length': data.length
  }
};

console.log('🧪 直接测试DeepSeek API...');
console.log('API Key:', apiKey.substring(0, 10) + '...');
console.log('URL:', baseUrl);

const req = https.request(options, (res) => {
  console.log('状态码:', res.statusCode);
  console.log('响应头:', res.headers);

  let responseData = '';

  res.on('data', (chunk) => {
    responseData += chunk;
  });

  res.on('end', () => {
    console.log('响应内容:', responseData);
    
    try {
      const jsonResponse = JSON.parse(responseData);
      if (jsonResponse.choices && jsonResponse.choices[0]) {
        console.log('✅ API调用成功！');
        console.log('AI回复:', jsonResponse.choices[0].message.content);
      } else {
        console.log('❌ API响应格式异常');
        console.log('完整响应:', JSON.stringify(jsonResponse, null, 2));
      }
    } catch (e) {
      console.log('❌ 解析响应失败:', e.message);
      console.log('原始响应:', responseData);
    }
  });
});

req.on('error', (e) => {
  console.error('❌ 请求失败:', e.message);
});

req.write(data);
req.end();

